//
//  KJButton.m
//  AnItemForACar
//
//  Created by wangkejie on 16/8/28.
//  Copyright © 2016年 shiying. All rights reserved.
//

#import "KJButton.h"

@interface KJButton ()

@property (nonatomic, weak) buttonAction action;

@end

@implementation KJButton

+ (instancetype)buttonType:(UIButtonType)type Frame:(CGRect)frame image:(UIImage *)image title:(NSString *)title {
    
    KJButton * button = [super buttonWithType:type];//button的类型
    button.frame = frame;
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 30, 30)];
    imageView.centerX = frame.size.width/2;
    imageView.image = image;
    [button addSubview:imageView];
    
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, imageView.bottom + 15, frame.size.width, kFontSysSize)];
    label.text = title;
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:kFontSysSize];
    label.textAlignment = NSTextAlignmentCenter;//设置title的字体居中
    [button addSubview:label];
    
    return button;
}

+ (instancetype)buttonWithFrame:(CGRect)frame title:(NSString *)title {
    KJButton * button = [super buttonWithType:UIButtonTypeSystem];
    button.frame = frame;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [button setBackgroundColor:AppMainColor];
    button.layer.cornerRadius = 3;
    return button;
}

/**
 *  底色appMainColor，白色字题,带圆角
 *
 *  @param frame frame
 *  @param title title
 *
 *  @return
 */
+ (instancetype)buttonWithFrame:(CGRect)frame title:(NSString *)title radius:(CGFloat)radius {
    KJButton * button = [KJButton buttonWithFrame:frame title:title];
    
    button.layer.cornerRadius = radius;
    
    return button;
}

/**
 *  底色appMainColor，白色字题,高度的0.5倍切圆角
 *
 *  @param frame frame
 *  @param title title
 *
 *  @return
 */
+ (instancetype)buttonWithCirleFrame:(CGRect)frame title:(NSString *)title {
    KJButton * button = [KJButton buttonWithFrame:frame title:title];
    
    button.layer.cornerRadius = frame.size.height / 2;
    
    return button;
}

@end
